\defmodule {UniformIntGen}

This class implements a random variate generator for the 
{\em uniform\/} distribution over integers, over the interval $[i,j]$.
Its mass function is
\begin{htmlonly}
\eq
   p(x) = 1 / (j - i + 1)  \qquad\mbox{ for } x = i, i + 1, \ldots, j
   \eqlabel{eq:fmassuniformint}
\endeq
\end{htmlonly}%
\begin{latexonly}
\eq
   p(x) = \frac{1}{j - i + 1}  \qquad\mbox{ for } x = i, i + 1, \ldots, j
   \eqlabel{eq:fmassuniformint}
\endeq
\end{latexonly}
and 0 elsewhere.

\bigskip\hrule

\begin{code}
\begin{hide}
/*
 * Class:        UniformIntGen
 * Description:  random variate generator for the uniform distribution over integers
 * Environment:  Java
 * Software:     SSJ 
 * Copyright (C) 2001  Pierre L'Ecuyer and Universite de Montreal
 * Organization: DIRO, Universite de Montreal
 * @author       
 * @since

 * SSJ is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License (GPL) as published by the
 * Free Software Foundation, either version 3 of the License, or
 * any later version.

 * SSJ is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * A copy of the GNU General Public License is available at
   <a href="http://www.gnu.org/licenses">GPL licence site</a>.
 */
\end{hide}
package umontreal.iro.lecuyer.randvar;\begin{hide}
import umontreal.iro.lecuyer.rng.*;
import umontreal.iro.lecuyer.probdist.*;
\end{hide}

public class UniformIntGen extends RandomVariateGenInt \begin{hide} {
   protected int left;     // the left limit of the interval
   protected int right;    // the right limit of the interval
    
\end{hide}
\end{code}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection* {Constructors}
\begin{code}

   public UniformIntGen (RandomStream s, int i, int j) \begin{hide} {
      super (s, new UniformIntDist (i, j));
      setParams (i, j);
   }\end{hide}
\end{code}
  \begin{tabb} Creates a uniform random variate generator over the integers
  in the closed interval $[i, j]$, using stream \texttt{s}. 
 \end{tabb}
\begin{code}

   public UniformIntGen (RandomStream s, UniformIntDist dist) \begin{hide} {
      super (s, dist);
      if (dist != null)
         setParams (dist.getI(), dist.getJ());
   }\end{hide}
\end{code}
  \begin{tabb} Creates a new generator for the distribution \texttt{dist}, using 
    stream \texttt{s}.  
 \end{tabb}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection* {Methods}
\begin{code}

   public static int nextInt (RandomStream s, int i, int j) \begin{hide} {
      return UniformIntDist.inverseF (i, j, s.nextDouble());
   }\end{hide}
\end{code}
\begin{tabb} Generates a new {\em uniform\/} random variate over the interval
   $[i,j]$, using stream \texttt{s}, by inversion.
\end{tabb}
\begin{code}

   public int getI()\begin{hide} {
      return left;
   }\end{hide}
\end{code}
  \begin{tabb}
  Returns the parameter $i$.
 \end{tabb}
\begin{code} 

   public int getJ()\begin{hide} {
      return right;
   }\end{hide}
\end{code}
  \begin{tabb}
  Returns the parameter $j$.
 \end{tabb}
\begin{hide}\begin{code}

   protected  void setParams (int i, int j) {
      if (j < i)
        throw new IllegalArgumentException ("j < i");
      left = i;
      right = j;
   }
}\end{code}
\end{hide}

